import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '订单号',
    align: 'center',
    dataIndex: 'orderNumber',
  },
  {
    title: '门店',
    align: 'center',
    dataIndex: 'shopId_dictText',
    customRender({ value, text, record }) {
      if (record.checkerInfo) {
        return '核销员：' + record.checkerInfo.lastName;
      }
      if (value == '-1') {
        return '-';
      }
      return text;
    },
  },
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'produName',
    width: '400px',
  },
  {
    title: '商品总量',
    align: 'right',
    dataIndex: 'productNums',
    width: '100px',
  },
  {
    title: '订单状态',
    align: 'center',
    dataIndex: 'status_dictText',
    width: 100,
    customRender({ value, record }) {
      if (record.refundSts == 1) {
        return h(
          'div',
          {
            style: 'color:red',
          },
          '待退款'
        );
      } else if (record.refundSts == 2) {
        return '已退款';
      }
      return value;
    },
  },
  {
    title: '配送类型',
    align: 'center',
    dataIndex: 'dvyType',
    width: 100,
    customRender({ value }) {
      if (value == 1) {
        return '门店自提';
      }
      return '快递配送';
    },
  },
  {
    title: '商品总额',
    align: 'right',
    dataIndex: 'total',
    width: 100,
  },
  {
    title: '运费',
    align: 'right',
    dataIndex: 'freightAmount',
    width: 50,
  },
  {
    title: '减免金额',
    align: 'right',
    dataIndex: 'reduceAmount',
    width: 100,
  },
  {
    title: '订单总额',
    align: 'right',
    dataIndex: 'actualTotal',
    width: 100,
  },
  {
    title: '备注',
    align: 'center',
    dataIndex: 'remarks',
  },
  {
    title: '快递单号',
    align: 'center',
    dataIndex: 'dvyFlowId',
  },
  {
    title: '用户地址',
    align: 'center',
    dataIndex: 'addrOrderId',
    customRender({ record }) {
      console.log(record.addressInfo);
      if (record.addressInfo) {
        return record.translateAddressInfo;
      }
      return '未知';
    },
    ellipsis: true,
  },
  {
    title: '支付时间',
    align: 'center',
    dataIndex: 'payTime',
  },
  {
    title: '配送时间',
    align: 'center',
    dataIndex: 'dvyTime',
  },
  {
    title: '取消时间',
    align: 'center',
    dataIndex: 'cancelTime',
  },
  {
    title: '用户',
    align: 'center',
    dataIndex: 'userId_dictText',
    width: 100,
  },
  {
    title: '供应商',
    align: 'center',
    dataIndex: 'supplierId_dictText',
    width: 200,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '订单号',
    field: 'orderNumber',
    component: 'JInput',
  },
  {
    label: '订单状态',
    field: 'status',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'order_status',
    },
  },
  {
    label: '售后状态',
    field: 'refundSts',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '待退款',
          value: 1,
        },
        {
          label: '已退款',
          value: 2,
        },
      ],
    },
  },
  {
    label: '创建日期',
    field: 'createTimeFieldTime',
    component: 'RangeDate',
  },
  {
    label: '支付日期',
    field: 'payTimeFieldTime',
    component: 'RangeDate',
  },
];
export const detailSearchFormSchema: FormSchema[] = [
  {
    label: '订单号',
    field: 'orderNumber',
    component: 'Input',
  },
  {
    label: 'SKU条形码',
    field: 'skuBarCode',
    component: 'Input',
  },
  {
    label: 'SPU条形码',
    field: 'spuBarCode',
    component: 'Input',
  },
  {
    label: '订单状态',
    field: 'status',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'order_status',
    },
  },
  {
    label: '售后状态',
    field: 'refundSts',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '待退款',
          value: 1,
        },
        {
          label: '已退款',
          value: 2,
        },
      ],
    },
  },
  {
    label: '创建日期',
    field: 'createTimeFieldTime',
    component: 'RangeDate',
  },
  {
    label: '支付日期',
    field: 'payTimeFieldTime',
    component: 'RangeDate',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '订单号',
    field: 'orderNumber',
    component: 'Input',
    dynamicDisabled() {
      return true;
    },
    colProps: { span: 12 },
  },
  {
    label: '快递单号',
    field: 'dvyFlowId',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    label: '商品总额',
    field: 'total',
    component: 'InputNumber',
    dynamicDisabled() {
      return true;
    },
    colProps: { span: 12 },
  },
  {
    label: '订单总额',
    field: 'actualTotal',
    component: 'InputNumber',
    dynamicDisabled() {
      return true;
    },
    colProps: { span: 12 },
  },
  {
    label: '用户备注',
    field: 'remarks',
    component: 'Input',
    dynamicDisabled() {
      return true;
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  shopId: { title: '门店标识', order: 0, view: 'text', type: 'string' },
  produName: { title: '商品名称', order: 1, view: 'text', type: 'string' },
  orderNumber: { title: '订单号', order: 2, view: 'text', type: 'string' },
  total: { title: '商品总额', order: 3, view: 'number', type: 'number' },
  acutalTotal: { title: '订单总额', order: 4, view: 'number', type: 'number' },
  payType: { title: '支付类型', order: 5, view: 'text', type: 'string' },
  remarks: { title: '备注', order: 6, view: 'text', type: 'string' },
  status: { title: '订单状态', order: 7, view: 'text', type: 'string' },
  dvyType: { title: '配送类型', order: 8, view: 'text', type: 'string' },
  dvyFlowId: { title: '快递单号', order: 9, view: 'text', type: 'string' },
  freightAmount: { title: '运费', order: 10, view: 'number', type: 'number' },
  addrOrderId: { title: '用户地址', order: 11, view: 'text', type: 'string' },
  productNums: { title: '商品总量', order: 12, view: 'number', type: 'number' },
  payTime: { title: '支付时间', order: 13, view: 'datetime', type: 'string' },
  dvyTime: { title: '配送时间', order: 14, view: 'datetime', type: 'string' },
  finallyTime: { title: '结束时间', order: 15, view: 'datetime', type: 'string' },
  isPayed: { title: '是否支付', order: 16, view: 'number', type: 'number' },
  cancelTime: { title: '取消时间', order: 17, view: 'datetime', type: 'string' },
  deleteStatus: { title: '删除状态', order: 18, view: 'number', type: 'number' },
  refundSts: { title: '回退状态', order: 19, view: 'number', type: 'number' },
  reduceAmount: { title: '减免金额', order: 20, view: 'number', type: 'number' },
  orderType: { title: '订单类型', order: 21, view: 'number', type: 'number' },
  closeType: { title: '关闭类型', order: 22, view: 'number', type: 'number' },
  userId: { title: '用户', order: 23, view: 'text', type: 'string' },
  supplierId: { title: '供应商', order: 24, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
